import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import './assets/styles/nomalize.css'
import HTTP from './utils/http'

Vue.config.productionTip = false;
Vue.use(ElementUI);
Vue.prototype.$http = HTTP(store, router);

// const whiteList = ['/login']

// const sessionId = store.state.sessionId;
// router.beforeEach((to, from, next) => {
//   if(whiteList.indexOf(to.path) < 0){
//     if(sessionId){
//       if(store.getters.roles.length === 0){
//         store.dispatch('GetInfo').then(res => {
//           const roles = res.data.role
//           store.dispatch('GenerateRoutes', {roles}).then(() => {
//             router.addRoutes(store.getters.addRouters)
//             next({...to,replace: true})
//           })
//         }).catch(err => {
//           console.log(err)
//         })
//       } else {
//         next()
//       }
//     } else {
//       next({path: '/login'})
//     }
//   } else {
//     next()
//   }
// })

// const token = store.state.token
// router.beforeEach((to, from, next) => {
//   if(whiteList.indexOf(to.path) < 0){
//     if(token){
//       next()
//     } else {
//       next({path: '/login'})
//     }
//   } else {
//     next()
//   }
// })

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app');
